package chapter9;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.concurrent.Callable;

/**
 * Created with IntelliJ IDEA.
 * Description:
 *
 * @author lzy
 * @create 2018-03-20 上午10:58
 */
public class TicketThread2 implements Callable<String> {
    private static final Logger LOGGER = LoggerFactory.getLogger(TicketThread.class);
    private int ticket = 5;
    private String name;

    public TicketThread2(String name) {
        this.name = name;
    }

    @Override
    public String call() throws Exception {
        for (int i = 0; i < 50; i++) {
            if (this.ticket > 0) {
                Thread.sleep(1000);
                LOGGER.info("[{}] Current thread-{} sell one ticket-{}", this.name, Thread.currentThread().getName(), ticket--);
            }
        }
        return "ticket sell out!";
    }
}
